﻿Imports System
Imports System.Collections.ObjectModel
Imports System.Drawing
Imports System.Workflow.ComponentModel
Imports System.Workflow.ComponentModel.Design

Namespace System.Workflow.Activities
    <ActivityDesignerTheme(GetType(ListenDesignerTheme))> _
    Friend NotInheritable Class ListenDesigner
        Inherits ParallelActivityDesigner
        ' Methods
        Public Overrides Function CanInsertActivities(ByVal insertLocation As HitTestInfo, ByVal activitiesToInsert As ReadOnlyCollection([Of] Activity)) As Boolean
            Dim activity As Activity
            For Each activity In activitiesToInsert
                If Not TypeOf activity Is EventDrivenActivity Then
                    Return False
                End If
            Next
            Return MyBase.CanInsertActivities(insertLocation, activitiesToInsert)
        End Function

        Protected Overrides Function OnCreateNewBranch() As CompositeActivity
            Return New EventDrivenActivity
        End Function

        Protected Overrides Sub OnPaint(ByVal e As ActivityDesignerPaintEventArgs)
            MyBase.OnPaint(e)
            If ((Me.Expanded AndAlso (Me.ContainedDesigners.Count <> 0)) AndAlso (Me Is MyBase.ActiveView.AssociatedDesigner)) Then
                Dim designerTheme As CompositeDesignerTheme = [TryCast](e.DesignerTheme,CompositeDesignerTheme)
                If (Not designerTheme Is Nothing) Then
                    Dim bounds As Rectangle = MyBase.Bounds
                    Dim imageRectangle As Rectangle = Me.ImageRectangle
                    Dim empty As Rectangle = Rectangle.Empty
                    empty.Width = ((designerTheme.ConnectorSize.Height - (2 * e.AmbientTheme.Margin.Height)) - 1)
                    empty.Height = empty.Width
                    empty.X = ((bounds.Left + (bounds.Width / 2)) - (empty.Width / 2))
                    empty.Y = ((bounds.Top + Me.TitleHeight) + ((((designerTheme.ConnectorSize.Height * 3) / 2) - empty.Height) / 2))
                    e.Graphics.FillEllipse(designerTheme.ForegroundBrush, empty)
                    e.Graphics.DrawEllipse(designerTheme.ForegroundPen, empty)
                    empty.Y = ((bounds.Bottom - ((designerTheme.ConnectorSize.Height * 3) / 2)) + ((((designerTheme.ConnectorSize.Height * 3) / 2) - empty.Height) / 2))
                    e.Graphics.FillEllipse(designerTheme.ForegroundBrush, empty)
                    e.Graphics.DrawEllipse(designerTheme.ForegroundPen, empty)
                End If
            End If
        End Sub

    End Class
End Namespace

